Skip to content

[WIP] Inconsistencies and improvements to SST model #2329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 75 commits into
base: develop
Choose a base branch
from

Conversation

rois1995
Copy link
Contributor

@rois1995 rois1995 commented Jul 25, 2024

Proposed Changes

Hi everyone,

I have found some inconsistencies with respect to the literature on the implementation of the Menter's SST model. I would like to use this branch as test bench for any corrections/improvements made to the SST model.

Implementation errors found:

  • Use of production limiter constant in the clipping of the cross-diffusion term for the computation of the F1 blending function in CTurbSSTVariable.cpp.
  • SST naming conventions (V in V2003m should stay for Vorticity production term.). Not yet assessed.
  • Wrong cross-diffusion term included into the residual of w in turb_sources.hpp. It should not be only the positive value as considered in the computation of the F1 blending function. As stated in https://doi.org/10.2514/3.12149. "CDkw is the
    positive portion of the cross-diffusion term in Eq (A2)" pag. 1604. Moreover, a clipping has been introduced for large negative values of this term, as suggested in Peng, Shia-Hui, Peter Eliasson, and Lars Davidson. "Examination of the shear stress transport assumption with a low-Reynolds number k-omega model for aerodynamic flows." Eq 17.
  • Boundary conditions errors at inlets, following the Issue Turbulent Kinetic Energy(TKE) on energy equation in SST model. #1851. A fix has been proposed following @pcarruscag suggestions for the supersonic inlet BC.
  • Boundary conditions definitions are different than the ones proposed in TMR. Maybe give the user the choice to use the BCs implemented in SU2 or the ones from TMR.

Changes to SST model proposed:

  • Inclusion of non modified versions of SST. In this case I think that more work is needed to be sure that the correct terms are taken into account everywhere in the code.
  • Give the user the possibility of changing the production limiter for TKE (not essential).
  • Change values of default turbulent to laminar viscosity to 1e-2 (NASA TMR reports that it should be in the range of 1e-2 to 1e-5, but in SU2 this is set to 10 as default).

I've seen the proposed changes to the lower limits of k and w in #2323 and I tried implementing it in my branch. However, if the implementation proposed in the respective PR is preferred then I will change mine.

Related Work

#2323 #1851

PR Checklist

Put an X by all that apply. You can fill this out after submitting the PR. If you have any questions, don't hesitate to ask! We want to help. These are a guide for you to know what the reviewers will be looking for in your contribution.

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with --warnlevel=3 when using meson).
  • My contribution is commented and consistent with SU2 style (https://su2code.github.io/docs_v7/Style-Guide/).
  • I used the pre-commit hook to prevent dirty commits and used pre-commit run --all to format old commits.
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp), if necessary.

@rois1995 rois1995 changed the title Inconsistencies and improvements to SST model [WIP] Inconsistencies and improvements to SST model Jul 25, 2024
Comment on lines 859 to 860
nPrandtl_Lam, /*!< \brief Number of species
addDoubleOption("FREESTREAM_TURB2LAMVISCRATIO", TurbIntensityAndViscRatioFreeStream[1], 10.0); Prandtl number. */
Copy link
Contributor

@bigfooted bigfooted Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this intentionally commented, or...? If it is used, I guess this should go to line 872

Suggested change
nPrandtl_Lam, /*!< \brief Number of species
addDoubleOption("FREESTREAM_TURB2LAMVISCRATIO", TurbIntensityAndViscRatioFreeStream[1], 10.0); Prandtl number. */
nPrandtl_Lam, /*!< \brief Number of species laminar Prandtl number. */
addDoubleOption("FREESTREAM_TURB2LAMVISCRATIO", TurbIntensityAndViscRatioFreeStream[1], 10.0); /*!<\brief Freestream mu_turb to mu_lam viscosity ratio */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a wrong copy-paste from me. It should not be there in the first place.

@bigfooted
Copy link
Contributor

Great contribution, Thanks @rois1995 !

@pcarruscag
Copy link
Member

If you are looking into robustness aspects too you should get in touch with @emaberman and @YairMO, seems like they have some good ideas and between the free time of 3 people a lot more can get done :)

@YairMO
Copy link

YairMO commented Jul 25, 2024

Hi,

Regarding the cross-diffusion term (CD) that appears in Omega source term (residual). The SST model (1994/2003) is a high-Reynolds-number model. Namely, It can not predict correctly the sub-layer region (especially the correct profile of the TKE). Therefore, only a positive contribution is required. Moreover, since the SST model was design as a k-w and k-epsilon blending, the CD term "belongs" only to the k-epsilon "branch", that is why the CD term include the factor "1-F1". However, it may happen, that the factor "1-F1" is not a 100% safe guarantee. It may happen that "1-F1" is not zero in region where the CD term is negative (this happen due numerical errors). To avoid such a situation, it is a good idea to clip the CD term with zero. Otherwise, severe numerical robustness issues may rise.
Yes, it is different from Menter publications, but I think that clipping the CD term with zero is completely inline with Menter original idea (that is why, I think, he was including the factor "1-F1". But again the 1-F1 factor is not 100% percent "safe").

- Given option for cross diffusion limiting in W residual
@YairMO
Copy link

YairMO commented Jul 26, 2024

Hi,

The use of an Omega production limiter (about the cross-diffusion term) is correct for low-Reynolds-number (LRN) models (the approach described by Peng et al. is very naive; there are other more rigorous treatments). For high-Reynolds-number (HRN) models, the clipping should be zero, keeping the cross-diffusion term positive; thus, the current implementation is correct.

Indeed, it is not exactly as it appears in Menter's original publication. The factor (1-F1) aimed to promise that the cross-diffusion term will be activated only outside the boundary layer, where it is positive (the cross-diffusion term switches its sign deep inside the boundary layer). This was also recognized by Peng et al. (first paragraph above Eq. 17). However, it may happen that the factor (1-F1)=1 where the cross-diffusion term is negative. Usually, it may happen at the wake, very near the airfoil trailing edge, where the upper and lower boundary layers merge. It is due to the imperfection of the F1 function.

To summarize, the current implementation is correct, and it is perfect for HRN models.

@YairMO
Copy link

YairMO commented Jul 26, 2024

For the sake of clarity, "current implementation" refers to the current treatment of the production code

@emaberman
Copy link
Contributor

What YairMO is saying, is that allowing negative cross diffusion values is incorrect for high Reynolds models and should not be an option, this is a fix used for low Reynolds models only

@rois1995
Copy link
Contributor Author

rois1995 commented Jul 26, 2024

Hi @YairMO, Hi @emaberman ,

thank you very much for your comments. I haven't found any suggestion in literature to clip to only positive values the cross-diffusion term in the w-equation. I understand that it might be more robust, but it is not the standard implementation of the SST model, which is the first thing that we need to achieve. Only then we can build on top of that to improve the robustness of SU2.

Nevertheless, I tried the SWBLI test case and I compared the results across 6 different combinations:

1- develop branch, no changes
2- develop branch, changes to Supersonic_inlet profile as suggested in #1851
3- my branch, with original CDkw implementation (should give exactly the same result as develop+modified BC)
3- my branch, with original CDkw implementation and using boundary conditions from TMR
4- my branch, with original CDkw implementation and using your suggestions for lower limits for k and w.
5- my branch, allowing negative values of CDkw
6- my branch, allowing negative values of CDkw and using boundary conditions from TMR
7- my branch, allowing negative values of CDkw and using your suggestions for lower limits for k and w.
8- my branch, allowing negative values of CDkw, using boundary conditions from TMR and using your suggestions for lower limits for k and w.

When my branch is used, then the changes to the supersonic inlet BC are already in place.

I haven't achieved convergence with 1, 2 and 3. More precisely, 1 diverged right away (after 30 iterations), while 2 and 3 gave "FGMRES - Orthogonalization Failed" after 900ish iterations.

Here you can see the residuals for the different combinations.

OrigCDkw

NegCDkw

Unfortunately I will be busy with the AIAA Conference next week, thus I don't know how much I will be able to work on this. The next test case will be the 2D airfoil near-wake from TMR.

@YairMO
Copy link

YairMO commented Jul 26, 2024

Hi rois1995,

First of all, enjoy your time in Las Vegas. Any paper that you are presenting?

As for our discussion about the cross-diffusion term, I've emailed the "source" (Menter). I believe he will make it clear.
It may be that he will be able to answer only in a while ...

@@ -865,7 +865,7 @@ class CConfig {
nMu_Temperature_Ref, /*!< \brief Number of species reference temperature for Sutherland model. */
nMu_S, /*!< \brief Number of species reference S for Sutherland model. */
nThermal_Conductivity_Constant,/*!< \brief Number of species constant thermal conductivity. */
nPrandtl_Lam, /*!< \brief Number of species laminar Prandtl number. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original description was correct, for species transport we can have a Prandtl number for each of the species

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I do not recall changing that but for sure it was wrong in my branch. Corrected, thanks!

su2double Omega_Freestream = 10 * ModVel_FreeStream / config->GetLDomain();
Tke_FreeStream = Omega_Freestream*(Viscosity_FreeStream*config->GetTurb2LamViscRatio_FreeStream())/Density_FreeStream;
} else if (config->GetSSTParsedOptions().sust) {
su2double Omega_Freestream = 5*ModVel_FreeStream/config->GetLength_Reynolds();

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable Omega_Freestream is not used.
* \param[in] iPoint - Point index.
* \return Value of magnitude.
*/
inline virtual su2double GetStrainMag(unsigned long iPoint) const {}

Check failure

Code scanning / CodeQL

Missing return statement Error

Function GetStrainMag should return a value of type su2double but does not return a value here

Copilot Autofix

AI 3 months ago

To fix the problem, we need to ensure that all execution paths in the function GetStrainMag return a value of type su2double. Since this is a virtual function, the base class implementation can return a default value, such as 0.0, which is a common practice for numerical functions. This will ensure that the function has a defined return value even if it is not overridden by derived classes.

Suggested changeset 1
SU2_CFD/include/variables/CVariable.hpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/SU2_CFD/include/variables/CVariable.hpp b/SU2_CFD/include/variables/CVariable.hpp
--- a/SU2_CFD/include/variables/CVariable.hpp
+++ b/SU2_CFD/include/variables/CVariable.hpp
@@ -1393,3 +1393,3 @@
    */
-  inline virtual su2double GetStrainMag(unsigned long iPoint) const {}
+  inline virtual su2double GetStrainMag(unsigned long iPoint) const { return 0.0; }
 
@@ -1399,3 +1399,3 @@
    */
-  inline virtual su2activevector& GetStrainMag() {}
+  inline virtual su2activevector& GetStrainMag() { static su2activevector default_vector; return default_vector; }
 
EOF
@@ -1393,3 +1393,3 @@
*/
inline virtual su2double GetStrainMag(unsigned long iPoint) const {}
inline virtual su2double GetStrainMag(unsigned long iPoint) const { return 0.0; }

@@ -1399,3 +1399,3 @@
*/
inline virtual su2activevector& GetStrainMag() {}
inline virtual su2activevector& GetStrainMag() { static su2activevector default_vector; return default_vector; }

Copilot is powered by AI and may make mistakes. Always verify output.
* \brief Get the entire vector of the rate of strain magnitude.
* \return Vector of magnitudes.
*/
inline virtual su2activevector& GetStrainMag() {}

Check failure

Code scanning / CodeQL

Missing return statement Error

Function GetStrainMag should return a value of type su2activevector & but does not return a value here

Copilot Autofix

AI 3 months ago

To fix the problem, we need to ensure that the function GetStrainMag returns a value of type su2activevector&. Since this is a virtual function, it is likely that derived classes will provide the actual implementation. However, we still need to provide a valid return value in the base class to avoid undefined behavior.

The best way to fix this issue without changing existing functionality is to return a reference to a static instance of su2activevector. This ensures that the function returns a valid reference, and it avoids the need to modify the function's signature or the class's interface.

Suggested changeset 1
SU2_CFD/include/variables/CVariable.hpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/SU2_CFD/include/variables/CVariable.hpp b/SU2_CFD/include/variables/CVariable.hpp
--- a/SU2_CFD/include/variables/CVariable.hpp
+++ b/SU2_CFD/include/variables/CVariable.hpp
@@ -1399,4 +1399,6 @@
    */
-  inline virtual su2activevector& GetStrainMag() {}
-
+  inline virtual su2activevector& GetStrainMag() {
+      static su2activevector dummy;
+      return dummy;
+  }
   /*!
EOF
@@ -1399,4 +1399,6 @@
*/
inline virtual su2activevector& GetStrainMag() {}

inline virtual su2activevector& GetStrainMag() {
static su2activevector dummy;
return dummy;
}
/*!
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +869 to +871
// su2double MeanReynoldsStress[3][3];
// ComputeStressTensor(nDim, MeanReynoldsStress, PrimVar_Grad_i + idx.Velocity(), Eddy_Viscosity_i,
// Density_i, ScalarVar_i[0]);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

Copilot Autofix

AI about 2 months ago

The best way to fix the problem is to remove the commented-out code entirely. This will make the code cleaner and easier to read, and it will eliminate any potential confusion about the commented-out sections. If the code is needed for future reference, it should be documented separately or added to version control comments.

  • Remove the commented-out code from lines 869 to 879.
  • Ensure that the remaining code is properly formatted and that no functionality is lost.
Suggested changeset 1
SU2_CFD/include/numerics/turbulent/turb_sources.hpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/SU2_CFD/include/numerics/turbulent/turb_sources.hpp b/SU2_CFD/include/numerics/turbulent/turb_sources.hpp
--- a/SU2_CFD/include/numerics/turbulent/turb_sources.hpp
+++ b/SU2_CFD/include/numerics/turbulent/turb_sources.hpp
@@ -867,16 +867,3 @@
         case SST_OPTIONS::COMP_ShuzHoff:{
-        
-          // su2double MeanReynoldsStress[3][3];
-          // ComputeStressTensor(nDim, MeanReynoldsStress, PrimVar_Grad_i + idx.Velocity(), Eddy_Viscosity_i, 
-          //                     Density_i, ScalarVar_i[0]);
-
-          // for (size_t iDim = 0.0; iDim < nDim; iDim++){
-          //   for (size_t jDim = 0.0; jDim < nDim; jDim++){
-          //     PDTerm += MeanReynoldsStress[iDim][jDim] * PrimVar_Grad_i[idx.Velocity() + iDim][jDim];
-          //   }
-          // }
-          // PDTerm = (-alpha2*PDTerm + alpha3 * epsilon * Density_i)*Mt*Mt;
-
           zetaFMt = alpha1 * Mt*Mt * (1-F1_i);
-          
           P_Base = StrainMag_i;
EOF
@@ -867,16 +867,3 @@
case SST_OPTIONS::COMP_ShuzHoff:{

// su2double MeanReynoldsStress[3][3];
// ComputeStressTensor(nDim, MeanReynoldsStress, PrimVar_Grad_i + idx.Velocity(), Eddy_Viscosity_i,
// Density_i, ScalarVar_i[0]);

// for (size_t iDim = 0.0; iDim < nDim; iDim++){
// for (size_t jDim = 0.0; jDim < nDim; jDim++){
// PDTerm += MeanReynoldsStress[iDim][jDim] * PrimVar_Grad_i[idx.Velocity() + iDim][jDim];
// }
// }
// PDTerm = (-alpha2*PDTerm + alpha3 * epsilon * Density_i)*Mt*Mt;

zetaFMt = alpha1 * Mt*Mt * (1-F1_i);

P_Base = StrainMag_i;
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +873 to +878
// for (size_t iDim = 0.0; iDim < nDim; iDim++){
// for (size_t jDim = 0.0; jDim < nDim; jDim++){
// PDTerm += MeanReynoldsStress[iDim][jDim] * PrimVar_Grad_i[idx.Velocity() + iDim][jDim];
// }
// }
// PDTerm = (-alpha2*PDTerm + alpha3 * epsilon * Density_i)*Mt*Mt;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

Copilot Autofix

AI about 2 months ago

To fix the problem, we should remove the commented-out code entirely. This will make the code cleaner and easier to read, and it will eliminate any potential confusion about whether the commented-out code is meant to be re-enabled or not.

  • Locate the commented-out code block starting at line 869 and ending at line 878.
  • Remove the entire block of commented-out code.
  • Ensure that the remaining code is properly formatted and that no functionality is lost.
Suggested changeset 1
SU2_CFD/include/numerics/turbulent/turb_sources.hpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/SU2_CFD/include/numerics/turbulent/turb_sources.hpp b/SU2_CFD/include/numerics/turbulent/turb_sources.hpp
--- a/SU2_CFD/include/numerics/turbulent/turb_sources.hpp
+++ b/SU2_CFD/include/numerics/turbulent/turb_sources.hpp
@@ -867,16 +867,3 @@
         case SST_OPTIONS::COMP_ShuzHoff:{
-        
-          // su2double MeanReynoldsStress[3][3];
-          // ComputeStressTensor(nDim, MeanReynoldsStress, PrimVar_Grad_i + idx.Velocity(), Eddy_Viscosity_i, 
-          //                     Density_i, ScalarVar_i[0]);
-
-          // for (size_t iDim = 0.0; iDim < nDim; iDim++){
-          //   for (size_t jDim = 0.0; jDim < nDim; jDim++){
-          //     PDTerm += MeanReynoldsStress[iDim][jDim] * PrimVar_Grad_i[idx.Velocity() + iDim][jDim];
-          //   }
-          // }
-          // PDTerm = (-alpha2*PDTerm + alpha3 * epsilon * Density_i)*Mt*Mt;
-
           zetaFMt = alpha1 * Mt*Mt * (1-F1_i);
-          
           P_Base = StrainMag_i;
EOF
@@ -867,16 +867,3 @@
case SST_OPTIONS::COMP_ShuzHoff:{

// su2double MeanReynoldsStress[3][3];
// ComputeStressTensor(nDim, MeanReynoldsStress, PrimVar_Grad_i + idx.Velocity(), Eddy_Viscosity_i,
// Density_i, ScalarVar_i[0]);

// for (size_t iDim = 0.0; iDim < nDim; iDim++){
// for (size_t jDim = 0.0; jDim < nDim; jDim++){
// PDTerm += MeanReynoldsStress[iDim][jDim] * PrimVar_Grad_i[idx.Velocity() + iDim][jDim];
// }
// }
// PDTerm = (-alpha2*PDTerm + alpha3 * epsilon * Density_i)*Mt*Mt;

zetaFMt = alpha1 * Mt*Mt * (1-F1_i);

P_Base = StrainMag_i;
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants